<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link rel="stylesheet" href="resource/css/bootstrap.css">
    <script src="resource/js/jquery-3.2.1.js"></script>
    <script src="resource/js/bootstrap.js"></script>
    <script type="text/javascript" src="/resource/My97DatePicker/WdatePicker.js"></script>
</head>
<body>
 <form>
     名称:<input  name="name" value="${spu.name}">
     标题:<input   name="title" value="${spu.title}">
     品牌:<select name="pid"  id="pid">
         </select>
     排序数据项:<select name="paixuid">
           <option value="">请选择</option>
           <option value="0">名称</option>
           <option value="1">标题</option>
           <option value="2">品牌</option>
           <option value="3">分类</option>
           <option value="4">是否上架</option>
    </select>
     排序方式:<select name="paixufangshi">
        <option value="">请选择</option>
        <option value="0">升序</option>
        <option value="1">降序</option>
    </select>
     <input type="button" onclick="sousuo()" value="搜索">
    <input type="button" value="添加" onclick="add()"><br>
     <input type="button" value="批量删除" onclick="ps()">
     <input type="button" value="全选" onclick="qx(true)">
     <input type="button" value="全不选" onclick="qx(false)">
     <input type="button" value="反选" onclick="fx()">
     <table class="table">
         <tr>
             <th>id</th>
             <th>名称</th>
             <th>图片</th>
             <th>品牌</th>
             <th>分类</th>
             <th>上架</th>
             <th>标题</th>
             <th>操作</th>
         </tr>
         <c:forEach items="${pg.list}" var="e">
             <tr>
                 <td><input type="checkbox" name="ck" value="${e.id}"> ${e.id}</td>
                 <td>${e.name}</td>
                 <td><img src="${e.picurl}" height="70px" width="50px"> </td>
                 <td>${e.pname}</td>
                 <td>${e.tname3}</td>
                 <td>${e.status==1?'上架':'下架'}</td>
                 <td>${e.title}</td>
                 <td><input type="button" onclick="xg(${e.id})" value="修改">
                     <input type="button" onclick="sc(${e.id})" value="删除">
                 </td>
             </tr>
         </c:forEach>
         <tr>
             <td colspan="8">
                 <input type="button" name="pageNum" onclick="goPage(1)" value="首页">
                 <input type="button" name="pageNum" onclick="goPage(${pg.prePage==0?'1':pg.prePage})" value="上一页">
                 <c:forEach items="${pg.navigatepageNums}" var="i">
                     <input type="button" name="pageNum" onclick="goPage(${i})" value="${i}">
                 </c:forEach>
                 <input type="button" name="pageNum" onclick="goPage(${info.nextPage==0?pg.pages:pg.nextPage})" value="下一页">
                 <input type="button" name="pageNum" onclick="goPage(${pg.pages})" value="尾页">
             </td>
         </tr>
     </table>

 </form>
 <script>
     function ps(){

         var array = new Array();
         $("[name='ck']:checked").each(function(i){
             array[i]=this.value;
         })
        alert(array)

         if(confirm("你确定要删除这些数据吗")){
             $.post("deleteByid",{ids:array},function(msg){
                 if(msg>0){
                     alert("删除成功")
                     location.reload();
                 }else{
                     alert("删除失败")
                     location.reload();
                 }
             })
         }
     }
     function qx(flag){
         $("[name='ck']").each(function(){
             $(this).attr("checked",flag)
         })
     }
     function fx(){
         $("[name='ck']").each(function(){
             this.checked=!this.checked
         })
     }
     $("[name='paixuid']").val('${spu.paixuid}')
     $("[name='paixufangshi']").val('${spu.paixufangshi}');
     function xg(ids){
         findAll("selectByid?ids="+ids)
     }
     function goPage(pageNum){
         findAll("list?pageNum="+pageNum);
     }
     function sousuo(){
         findAll("list?"+$("form").serialize())
     }

     $.post("selectBypid",function(msg){
         var str="<option value=''>请选择</option>"
         for(var i in msg){
             str+="<option value='"+msg[i].id+"'>"+msg[i].pname+"</option>";
         }
         $("#pid").html(str);
         $("#pid").val('${spu.pid}')
     })
     function add(){
         findAll('toadd')
     }
 </script>
</body>


</html>